<!--
(function(){

var 

window = this,

undefined ,

//web dir
d = function(dir) {
	return dir === undefined ? eva.config.dir : eva.config.dir + dir;
},

s = function(dir){
	return dir === undefined ? eva.config.s : eva.config.s + dir;
},

f = function(dir){
	return dir === undefined ? eva.config.f : eva.config.f + dir;
},

p = function (m){
	if(typeof console === 'undefined')
		return alert(m);
	return console.log(m);
},


igal = window.igal = {

	config : {
		debug : false,
		scenSelector : "#scen",
		scenOrignalWidth : 800,
		scenOrignalHeight : 600,
		scenWidth : 1024,
		scenHeight : 768,
		project : 'mo2',
		projectPath : '/projects/mo2',
		charactersPath : '/characters',
		charactersExt : 'png',
		musicsPath : '/musics',
		musicsExt : 'mp3',
		backgroundsPath : '/backgrounds',
		backgroundsExt : 'jpg',
		cgPath : '/cg'
	},

	p : function (m){
		return p(m);
	},

	d : function(dir) {
		return d(dir);
	},

	s : function(dir){
		return s(dir);
	},

	f : function(dir){
		return f(dir);
	},

	_scen : {
		title : '',	
		bg: '',
		music: '',
		dom : {}
	},

	_player : {},

	_section : {
		title : "",
		character : "",
		bg: '',
		music: '',
		dom : {}
	},

	_background : {
		dom : {}			  
	},

	_index : {
		scen : '',
		section : 0,
		p : 0
	},

	//do sth before load Jquery
	init : function(setting){

		if(setting) {
			igal.config = igal.lib.initConfig(config, setting);
		}

		var moduleName = '';
		for(moduleName in this.module){
			if(this.module[moduleName].init === undefined) {
				continue;
			}
			this.module[moduleName].init();
		}

		jQuery(document).ready(function () {
			igal.module.core.start();

		});
		
		//igal.module.background.change('beach_sandy_night');

	},

	//public functions lib
	lib : {
		initConfig : function(config, setting){
			var i;
			for(i in setting) {
				config[i] = setting[i];
			}
			return config;
		},
		trim : function(str){
			if(!String.prototype.trim){
				return str.replace(/^\s+|\s+$/g, '');
			}
		},

		preload : function() { 
			var cache = [];
			var args_len = arguments.length;
			for (var i = args_len; i--;) {
				var cacheImage = document.createElement('img');
				cacheImage.src = arguments[i];
				cache.push(cacheImage);
			}
		},

		loadcss : function() {
			var len = arguments.length;
			var head = document.getElementsByTagName("head")[0];
			var css = document.createElement('link');
			css.type = 'text/css';
			css.rel = "stylesheet";
			for(var i = 0; i < len; i++) {
				css.href = s(arguments[i]);
				head.appendChild(css);
			}
		},
		
		loader : function(path, callback) {
			if($LAB === undefined || path === undefined || !path) {
				return;
			}

			if(path[0] === undefined) {
				return $LAB.script( s(path) ).wait(callback);
			}

			for(var i in path) {
				path[i] = s(path[i]);
			}
			return $LAB.script(path).wait(callback);
		},

		template : function(template, replace){
			template = template.replace(/{[^{}]+}/g, function(key){
				return replace[key.replace(/[{}]+/g, "")] || "";
			});
			return template;
		}		  
	},

	module : {
		core : {
			start : function(){
				
					
			},

			pause : function(){
					
			},

			reset : function(){
					
			},

			save : function(){
				   
			},

			load : function(){
				   
			}
		},

		scen : {

			getScen : function(){
				return 	$(igal.config.scenSelector);
			},

			init: function(){
				var scen = $(igal.config.scenSelector);
				if(!scen[0]) {
					return false;
				}

				scen.addClass("scen").find("[data-role]").each(function(){
					$(this).addClass($(this).attr("data-role"));
				});				  


				for(var i in igal._scen) {
					igal._scen[i] = scen.attr("data-" + i);
				}

				igal.config.scenHeight = document.documentElement.clientHeight;
				igal.config.scenWidth = igal.config.scenHeight * igal.config.scenOrignalWidth / igal.config.scenOrignalHeight;
				p(igal.config.scenHeight);
				if(igal.config.scenWidth) {
					scen.width(igal.config.scenWidth);
					scen.height(igal.config.scenHeight);
				}

				igal._scen.dom = scen;
			}
			   
		},


		background : {

			getBackground : function(){
				return igal._background.dom;
			},

			getBackgroundPath : function(bgName){
				if(!bgName) {
					return igal.config.projectPath + igal.config.backgroundsPath + '/';
				}

				bgArr = bgName.split('_');
				return bgArr.length > 1 ? 
					igal.config.projectPath + igal.config.backgroundsPath + '/' +  bgArr.join('/') + '.' + igal.config.backgroundsExt		
					: igal.config.projectPath + igal.config.backgroundsPath + '/' +  bgName + '.' + igal.config.backgroundsExt;		
			},

			change : function(bgName){
				if(!bgName) {
					return false;
				}

				var background = this.getBackground();
				background.find('img').attr("src", this.getBackgroundPath(bgName));
			},

			init : function(){
				var scen = igal.module.scen.getScen();
				scen.append('<div class="background"><img src="' + this.getBackgroundPath(igal._scen.bg) + '" width="' + igal.config.scenWidth + '" /></div>');
				igal._background.dom = scen.find(".background");
			}			 
		},

		character : {

			getCharacterPath : function(characterName){
				return musicName ? 
					igal.config.projectPath + igal.config.charactersPath + '/' + characterName + '.' + gal.config.characterExt
					: igal.config.projectPath + igal.config.charactersPath + '/';
			},

			show : function(characterName){
				   
			},

			hide : function(characterName){
				   
			}
			
		},

		music : {
			getMusicPath : function(musicName){
				return musicName ? 
					igal.config.projectPath + igal.config.musicsPath + '/' +  musicName + '.' + gal.config.musicsExt
					: igal.config.projectPath + igal.config.musicsPath + '/';
			},

			getPlayer : function(){
				if(igal._player) {
					return igal._player;
				}

				if(!$("#player")[0]) {
					$("body").append('<div id="player"></div>');
				}
				gal.player = $('#player');
				gal.player.hide();

				gal.player.jPlayer({
					ready: function () {
						igal._player = $(this);
					},
					 swfPath: '/javascripts/jquery/'
				});
						
			},

			play : function(musicName){
				this.getPlayer().jPlayer("setMedia", {
					mp3: igal.module.music.getMusicPath(musicName)
				}).jPlayer("play");
			},

			init: function(){
				this.getPlayer();
			}		
		},

		script : {
			
			prev : function(){
				   
			},

			next : function() {
				   
			},

			show : function() {
				   
			},

			hide : function() {
				   
			},

			init : function(){
				   
			}
				 
		},
		 
	}
};

})();



-->
